package com.ygo.feihua;

import android.app.*;
import android.content.*;
import android.os.*;
import android.widget.*;
import cn.bmob.v3.*;
import com.ygo.feihua.BmobTable.*;
import cn.bmob.v3.listener.*;
import java.util.*;
import android.widget.AdapterView.*;
import android.view.*;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
import cn.bmob.v3.exception.BmobException;
import android.support.v4.util.*;
import com.ygo.feihua.util.*;
import com.ygo.feihua.Management.*;

public class KadianDianxian extends Activity
{
	List<Map<String,Object>> list=new ArrayList<Map<String,Object>>();
	
	TextView kd_dt;
	ListView kd_list;
	Kditem ki;
	ProgressDialog pd1;
	Gongju gj;
	private DialogUtils du;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		// TODO: Implement this method
		super.onCreate(savedInstanceState);
		setContentView(R.layout.kadian_dianxian);
		SdkInitManagement.getDx().initBaiduMapSdk();
		gj=Gongju.getdx(this);
		du=DialogUtils.getdx(this);
		
		kd_dt=(TextView) findViewById(R.id.kd_dt);
		kd_list=(ListView) findViewById(R.id.kd_list);
		du.dialogj1(false,"","查询中,请稍等");
        
		Intent intent = this.getIntent();
		String cheng = intent.getStringExtra("cs");
		
		kd_dt.setText("位于"+cheng+"的卡店");
    
		BmobQuery<Kadian> kd=new BmobQuery<Kadian>();
		kd.addWhereEqualTo("kdsh",1);
		kd.addWhereEqualTo("kd_cs",cheng);
		kd.order("-createdAt");
		kd.findObjects( new FindListener<Kadian>(){

				@Override
				public void done(List<Kadian> p1, BmobException p2)
				{
					if(p2==null){
						if(p1.size()==0){
							gj.show("这个城市还没有卡店哟,若有卡店可以通过认证卡店来上传");
							du.dis();
						}else{
							for(Kadian k:p1){
								Map<String,Object> map=new ArrayMap<String,Object>();
								map.put("name",k.getKd_name());
								map.put("dz",k.getKd_dz());		
								map.put("id",k.getObjectId());
								list.add(map);
							}
							ki=new Kditem(KadianDianxian.this,list);
							kd_list.setAdapter(ki);
							//		pd1.dismiss();
							du.dis();
						}
					}else{
						gj.toastBmobException(kd_list,"查询失败",p2);
						
					//	gj.show("查询失败"+p2.getMessage());
						du.dis();
					}
					
					
					
					// TODO: Implement this method
				}
				

				
			});
		kd_list.setOnItemClickListener(new OnItemClickListener(){

				@Override
				public void onItemClick(AdapterView<?> p1, View p2, int p3, long p4)
				{
					
					Intent intent1 =new Intent();
					intent1.setClass(KadianDianxian.this,KadianXiangxi.class);
					intent1.putExtra("id",(String)list.get(p3).get("id"));
					startActivity(intent1);
					
					// TODO: Implement this method
				}
			});
			
			
			
		
	}
	
}
